﻿using Assets.Scenes.Script;
using Assets.Scenes.Script.UI;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;

public class UIManager : MonoBehaviour
{
    public static UIManager Single;

    public TMP_InputField output;

    public GameObject pBox;
    public Transform pBoxParent;

    public GameObject btn;
    public Transform btnParent;

    public GameObject parmPanel;
    public TextMeshProUGUI InfoPanel;
    public TextMeshProUGUI nametext;

    // Start is called before the first frame update
    void Start()
    {
        Single = this;

        foreach (var item in ConfigReader.configs)
        {
            Instantiate(btn, btnParent).GetComponent<Btn>().Init(item);
        }

    }

    public void ShowParmPanel(ConfigItem configItem)
    {
        parmPanel.SetActive(true);
        nametext.text = configItem.btnName;
        if (configItem.pInFo != null)
        {
            InfoPanel.text = configItem.pInFo;
        }
        else
        {
            InfoPanel.text = "";
        }


        configItem.psValue = new string[configItem.psName.Length];
        for (int i = 0; i < configItem.psValue.Length; i++)
        {
            configItem.psValue[i] = "";
        }

        output.text = configItem.CMD;

        for (int i = 0; i < configItem.psName.Length; i++)
        {
            var pInputBox = Instantiate(pBox, pBoxParent).GetComponent<ParmInputBox>();
            pInputBox.Init(configItem, i);
        }

    }

    public void CloseParmPanel()
    {
        for (int i = 0; i < pBoxParent.transform.childCount; i++)
        {
            Destroy(pBoxParent.transform.GetChild(i).gameObject);
        }
        parmPanel.SetActive(false);
    }

    public void Copy()
    {
        GUIUtility.systemCopyBuffer = output.text.Trim();
    }

}
